<template>
  <div class="article">
    <div class="daohang">
      <RouterLink to="/layout/article/tuijian">推荐</RouterLink>
      <RouterLink to="/layout/article/zuixin">最新</RouterLink>
      <div class="img"></div>
    </div>
    <router-view></router-view>
    <div
      class="item"
      @click="$router.push({ path: '/detail/' + item.id })"
      v-for="item in list"
      :key="item.id"
    >
      <div class="top">
        <!-- <div class="left">1</div> -->
        <img :src="item.creatorAvatar" alt="" />
        <div class="right">
          <div class="title">{{ item.stem }}</div>
          <div class="username">
            <span>{{ item.creatorName }}</span>
            <span>|</span>
            <span>{{ item.createdAt }}</span>
          </div>
        </div>
      </div>
      <div class="middle">
        {{ item.content }}
      </div>
      <div class="bottom">
        <span>点赞 {{ item.likeCount }}</span>
        <span>|</span>
        <span>浏览 {{ item.views }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "HmArticle",
  data() {
    return {
      list: [],
      curent: 1,
      pageSize: 10,
    };
  },
  created() {
    this.getList();
  },
  activated() {
    console.log("每次页面激活时触发");
  },
  deactivated() {
    console.log("每次页面失活时触发");
  },
  // methods: {
  //   async getList() {
  //     const res = await axios({
  //       url: "http://interview-api-t.itheima.net/h5/interview/query",
  //       method: "get",
  //       params: {
  //         current: 1,
  //         pageSize: 10,
  //       },
  //       headers: {
  //         Authorization: ` Bearer ${this.$route.query.token}`,
  //       },
  //     });
  //     console.log(res);
  //     this.list = res.data.data.rows;
  //   },
  // },
  methods: {
    async getList() {
      const res = await axios({
        url: "https://mock.boxuegu.com/mock/3083/articles",
      });

      this.list = res.data.result.rows;
    },
  },
};
</script>

<style lang="less" scoped>
.item {
  padding: 10px;
  margin: 10px;
  border: 1px solid #000;
  .top {
    display: flex;

    img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }

    .right {
      flex: 1;
    }
  }
}
// 超过两行显示省略号
.middle {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.daohang {
  width: "100%";

  display: flex;
  justify-content: flex-start;
  padding: 10px;
  margin: 10px;
  .img {
    width: 45px;
    height: 20px;
    background-image: url("../assets/logo2.png");
    background-size: cover; /* 使背景图片覆盖整个元素 */
    background-position: center; /* 将背景图片居中 */
    background-repeat: no-repeat; /* 防止背景图片重复 */
    margin-left: auto;
  }
}
</style>
